import express from "express";
import bodyparser from "body-parser";
import cookieparser from "cookie-parser";
import cookiesession from "cookie-session";
import uuid from "uuid";
import consolidate from "consolidate";
import multer from "multer";
import logger from "morgan";
import cors from "cors";
import path from "path";
let multerobj=multer({dest:"./public/upload"});

let server=express();
server.listen(8081);
// server.use('/' ,express.static(path.join(__dirname,'public'));
server.use('/' ,express.static(path.join(__dirname,  'public')));

server.use(multerobj.any());
server.use(logger("dev"));
server.use(logger("combined",{stream:require("fs").createWriteStream("./logs/logs.log",{flags:"a"})}))

server.use(bodyparser.urlencoded({extended:true,limit:"500mb"}));
server.use(bodyparser.json());
server.use(bodyparser.text());

server.use(cors({
    origin:"*",
    methods:['GET','POST'],
    alloweHeaders:['Conten-Type', 'Authorization'],
    
}));
// server.all('*', function(req, res, next) {
//     res.header("Access-Control-Allow-Origin", "*");
//     res.header("Access-Control-Allow-Headers", "X-Requested-With");
//     res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");//允许的请求方式类型
//     res.header("X-Powered-By",' 3.2.1')
//     next();
// });

server.use(cookieparser("zhongchou"));
server.use(cookiesession({
    genid:function()
    {
        return uuid.v1();
    },
    maxAge:20*1000*60,
    secret:"zhongchou"
}))

server.set("view engine","html");
server.set("views","./views");
server.engine("html",consolidate.ejs);


server.use("/admin",require("./route/admin/adminroute"));
server.use("/client",require("./route/client/clientroute"));

 